package com.struc.td;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

//main menu class for the main menu state
public class MainMenu extends State{
	private Main main;
	private Texture menuButT;
	private Texture mainMenuT;
	private Sprite background;
	private Sprite newgame;
	private Sprite highscore;
	private Sprite soundOn;
	private Sprite soundOff;
	private Sprite currentSound;
	private SpriteBatch spriteBatch;
	private Sprite continueBut;
	private Sprite currentContinue;
	private int width;
	private int height;
	//constructor initiates textures and game sound
	public MainMenu(Main m) {
		main = m;
		Sounds.playMusic(Sounds.MUSIC_MUSIC);
		menuButT = new Texture(Gdx.files.internal("data/menu2but.png"));
		mainMenuT = new Texture(Gdx.files.internal("data/menu2comp.png"));
		background = new Sprite(mainMenuT, 0, 0 , 1024, 1024);
		newgame = new Sprite(menuButT,101,92,315,80);
		highscore = new Sprite(menuButT,106,182,327,75);
		soundOn = new Sprite(menuButT,88,257,346,94);
		soundOff = new Sprite(menuButT, 89, 349, 346, 94);
		continueBut = new Sprite(menuButT, 82, 25, 340, 68);
		spriteBatch = new SpriteBatch();
		width = Main.WIDTH;
		height = Main.HEIGHT;
	}
	//our update method is run to update the game interface.
	public void update() {
		width = Main.WIDTH;
		height = Main.HEIGHT;
		background.setSize(width, height);
		continueBut.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-120, 200, 50);
		newgame.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-60, 200, 50);
		highscore.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-180, 200, 50);
		soundOn.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-240, 200, 50);
		soundOff.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-240, 200, 50);
		if(!Sounds.getMuted()){
			currentSound = soundOn;
		} else {
			currentSound = soundOff;
		}
		if(main.getGameOn()){
			newgame.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-60, 200, 50);
			continueBut.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-120, 200, 50);
		} else {
			newgame.setBounds(Gdx.graphics.getWidth()/2-100, Gdx.graphics.getHeight()-120, 200, 50);
		}
	}

	//render method to render our main menu state
	public void render() {
		spriteBatch.begin();
		background.draw(spriteBatch);
		if (main.getGameOn()) {
			continueBut.draw(spriteBatch, 0.8f);
		}
		newgame.draw(spriteBatch,0.8f);
		highscore.draw(spriteBatch, 0.8f);
		currentSound.draw(spriteBatch, 0.8f);
		spriteBatch.end();
	}
	public void enter() {
		Gdx.input.setInputProcessor(this);
	}

	public boolean keyDown(int arg0) {
		return false;
	}

	public boolean keyTyped(char arg0) {
		return false;
	}

	public boolean keyUp(int arg0) {
		return false;
	}

	public boolean scrolled(int arg0) {
		return false;
	}

	public boolean touchDown(int x, int y, int arg2, int arg3) {
		y = height-y;
		if (newgame.getBoundingRectangle().contains(x,y)) {
			((Game)main.getState(2)).restart();
			main.setState(2);
			main.setGameOn(true);
		} else if (main.getGameOn() && continueBut.getBoundingRectangle().contains(x,y)) {
			main.setState(2);
		}
		else if( highscore.getBoundingRectangle().contains(x,y)){
			main.setState(3);
		}
		else if(currentSound.getBoundingRectangle().contains(x,y)){
			Sounds.mute();
		}
		return false;
	}

	public boolean touchDragged(int arg0, int arg1, int arg2) {
		return false;
	}

	public boolean touchMoved(int arg0, int arg1) {
		return false;
	}

	public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
		return false;
	}
}
